
#include <Archaism/Cache.h>

_BeginNamespace(Radix)

Cache::Cache(void* data, uint stride, uint count)
{
	this->assign(data, stride, count);
}

Cache::Cache(const Cache& cache)
{
	this->assign(cache.mData, cache.mStride, cache.mCount);
}

Cache::~Cache()
{
	this->clear();
}

Cache& Cache::operator=(const Cache& cache)
{
	if(this == &cache)
		return *this;
	return this->assign(cache.mData, cache.mStride, cache.mCount);
}

void* Cache::data() const
{
	return mData;
}

uint Cache::stride() const
{
	return mStride;
}

uint Cache::count() const
{
	return mCount;
}

uint Cache::length() const
{
	return mStride*mCount;
}


Cache& Cache::assign(void* data, uint stride, uint count)
{
	this->clear();
	mData = new uchar[stride*count];
	memcpy(mData, data, stride*count);
	mStride = stride;
	mCount = count;
	return *this;
}

void Cache::clear()
{
	if(mData != nullptr)
	{
		delete []mData;
		mData = nullptr;
	}
	mStride = 0;
	mCount = 0;
}

_EndNamespace(Radix)
